package com.classba.elasticsearch;

import org.apache.hadoop.hive.serde2.io.ByteWritable;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
import org.apache.hadoop.hive.serde2.io.ShortWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.elasticsearch.hadoop.hive.HiveValueReader;
import org.elasticsearch.hadoop.mr.WritableCompatUtil;
import org.elasticsearch.hadoop.serialization.Parser;

import java.nio.charset.StandardCharsets;


public class CustomizeEsValueReader extends HiveValueReader {


    @Override
    protected Object binaryValue(byte[] value) {
        return new Text(new String(value, StandardCharsets.UTF_8));
    }


    @Override
    protected Object byteValue(String value, Parser parser) {

        if (value == null) {
            return null;
        } else {
            return new Text(value);
        }
    }

    @Override
    protected Object shortValue(String value, Parser parser) {
        if (value == null) {
            return null;
        } else {
            return new Text(value);
        }
    }

    @Override
    protected Object intValue(String value, Parser parser) {
        if (value == null) {
            return null;
        } else {
            return new Text(value);
        }
    }


    @Override
    protected Object longValue(String value, Parser parser) {
        if (value == null) {
            return null;
        } else {
            return new Text(value);
        }
    }

    @Override
    protected Object floatValue(String value, Parser parser) {
        if (value == null) {
            return null;
        } else {
            return new Text(value);
        }
    }

    @Override
    protected Object doubleValue(String value, Parser parser) {
        if (value == null) {
            return null;
        } else {
            return new Text(value);
        }
    }



    @Override
    protected Object processLong(Long value) {
        return new Text(String.valueOf(value));
    }
    @Override
    protected Object processDouble(Double value) {
        return new Text(String.valueOf(value));
    }

    @Override
    protected Object processByte(Byte value) {
        return new Text(String.valueOf(value));
    }

    @Override
    protected Object processShort(Short value) {
        return new Text(String.valueOf(value));
    }

    @Override
    protected Object processInteger(Integer value) {
        return new Text(String.valueOf(value));
    }




}

